<template>
	<!-- 折扣设置 -->
	<view class="wp">
		<uni-forms :modelValue="formData" label-width="120px" label-position="top">
			<view class="message">
				当前店铺充值折扣成本<text>{{formData.discount}}</text>折
			</view>
			<view class="message">
				提示：折扣区间为1.00—10.00 (会员折扣需大于VIP折扣)
			</view>
			<uni-forms-item label="VIP折扣">
				<uni-easyinput type="digit" :clearable="false" v-model="formData.vd" placeholder="VIP折扣" />
			</uni-forms-item>
			<uni-forms-item label="会员折扣">
				<uni-easyinput type="digit" :clearable="false" v-model="formData.cd" placeholder="会员折扣" />
			</uni-forms-item>

			<view class="screen_submit">
				<button @click="screenSubmit">提交</button>
			</view>
		</uni-forms>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				uid: '',
				formData: {
					vd: '',
					cd: '',
					discount: '',
					
				},
			}
		},
		onLoad(option) {
			this.uid = option.uid;
			this.getInfo();
		},
		methods: {
			getInfo() {
				this.$axios('signing/showDiscount', 'POST', 'member', {
					uid: this.uid
				}).then(res => {
					if (res.data.code == 200) {
						this.formData = res.data.data;
					}
				}) 
			},
			screenSubmit() {
				if (this.formData.vd > 0 && this.formData.cd > 0 && this.formData.vd <= 10 && this.formData.cd <= 10 &&
					Number(this.formData.cd) >= Number(this.formData.vd)) {
						this.formData.uid=this.uid;
					this.$axios('signing/setDiscount', 'POST', 'member', {vd:this.formData.vd,cd:this.formData.cd,uid:this.uid}).then(res => {
						if (res.data.code == 200) {
							this.$api.msg('提交成功！');
							setTimeout(() => {
								this.$navBack();
							}, 700)
						}
					})
				} else {
					this.$api.msg('请正确填写折扣！');
				}
			}
		}
	}
</script>

<style lang="scss">
	.wp {
		color: #000;
		padding: 0 20upx;
	}

	.message {
		color: #4399fc;
		padding-bottom: 22px;
	}

	.screen_submit {
		button {
			background: $bg-color;
			color: #fff;
		}
	}
</style>